global filename "regs_curative"
cap erase "${filename}.csv"
use if inbcms==1 using "curative", clear


do "edit_beforeregs.do"
*g _month=month

estimates clear
cap noisily erase "${filename}"
				
*Main Table 
	foreach yvar in anysect anysect_cond {
	local yvarshort=substr("`yvar'",1,9)
	
		foreach control in basic demogplus mun {
		global controls ${c_`control'} 

				eststo a`yvarshort'`control': reg `yvar' eventviolent_mun i.month i.year i.provid  $controls, cluster(munid)
				sum eventviolent_mun if e(sample)==1, d
				local xvarmean=round(r(mean),.01)
				local xvarsd=r(sd)*_b[eventviolent_mun]
				
				estadd ysumm
				estadd local control "`control'"
				estadd local xvarmean "`xvarmean'"
				estadd local xvarsd "`xvarsd'"					

		}
		*control loop	
	}
	*yvar loop end
	esttab a* using "${filename}.csv", star(* 0.10 ** 0.05 *** .01) title("Curative Care Main Results") ///
		se(a2) b(a2) append keep(*eventviolent_mun* ) staraux scalar("ymean Mean of DV" "xvarsd 1SD effect" "control control"   "xvarmean xvarmean" ) 				
	estimates clear	
	
	*Selection Tests
	foreach yvar in $c_selection {
	local yvarshort=substr("`yvar'",1,9)
	
		foreach control in none {
		global controls ${c_`control'} 

				eststo a`yvarshort'`control': reg `yvar' eventviolent_mun i.provid $controls, cluster(munid)
				estadd ysumm
				estadd local control "`control'"
		

		}
		*control loop	
	}
	*yvar loop end
	esttab a* using "${filename}.csv", star(* 0.10 ** 0.05 *** .01) title("Selection (Contemporaneous Monthly)") ///
		se(a2) b(a2) append keep(*eventviolent_mun* ) staraux scalar("ymean Mean of DV"   "control control"   ) 				
	estimates clear		


*Heterogeneity
	foreach yvar in anysect  {
	local yvarshort=substr("`yvar'",1,9)
		
			foreach control in demogplus mun  {
			global controls ${c_`control'} 
				eststo a`yvarshort'`control': reg `yvar' eventviolent_mun c.eventviolent_mun#c.(f_tv f_radio) f_tv f_radio i.month i.year i.provid $controls, cluster(munid)
				estadd ysumm
				estadd local control "`control'"				

				
				eststo b`yvarshort'`control': reg `yvar' eventviolent_mun c.eventviolent_mun#c.(f_tv f_radio) f_tv f_radio c.eventviolent_mun#c.wealthscore i.month i.year i.provid $controls, cluster(munid)
				estadd ysumm
				estadd local control "`control'"				

				
				eststo c`yvarshort'`control': reg `yvar' eventviolent_mun c.eventviolent_mun#c.(ratioany) ratioany i.month i.year i.provid $controls, cluster(munid)
				estadd ysumm
				estadd local control "`control'"								
			}
			*control loop	
		}
		*yvar loop end
		
	esttab a* using "${filename}.csv", star(* 0.10 ** 0.05 *** .01) title("Curative Care Heterogeneity by TV/Radio") ///
		se(a2) b(a2) append keep(*eventviolent_mun* f_tv f_radio ) staraux scalar("ymean Mean of DV" "control control" ) 				
	esttab c* using "${filename}.csv", star(* 0.10 ** 0.05 *** .01) title("Curative Care Heterogeneity by Medical Workers") ///
		se(a2) b(a2) append keep(*eventviolent_mun* ratioany ) staraux scalar("ymean Mean of DV" "control control" ) 				
	esttab b* using "${filename}.csv", star(* 0.10 ** 0.05 *** .01) title("Curative Care Heterogeneity by TV/Radio with Wealth") ///
		se(a2) b(a2) append order(eventviolent_mun *#* f_tv f_radio wealthscore) keep(*eventviolent_mun* f_tv f_radio *wealthscore) staraux scalar("ymean Mean of DV" "control control" ) 				
	estimates clear	


*Types of Violence, Alternate Definitions of violence	
	foreach xvar in eventshoot_mun eventclash_mun eventkidnap_mun eventbomb_mun pc_eventviolent_mun pa_eventviolent_mun eventviolent_mun_last3 {
		local xvarshort=substr("`xvar'",1,7)
			
			foreach control in demogplus mun {
			global controls ${c_`control'} 
		

			eststo a`xvarshort'`control': reg anysect `xvar' i.month i.year i.provid  $controls, cluster(munid)
			sum `xvar' if e(sample)==1, d
			local xvarmean=round(r(mean),.01)
			local xvarsd=r(sd)*_b[`xvar']
			
			estadd ysumm
			estadd local control "`control'"
			estadd local xvarmean "`xvarmean'"
			estadd local xvarsd "`xvarsd'"	
	}
	*control loop end
		
	esttab a* using "${filename}.csv", star(* 0.10 ** 0.05 *** .01) title("Curative Care: `xvar'") ///
		se(a2) b(a2) append keep(*`xvar'* ) staraux scalar("ymean Mean of DV" "xvarsd 1SD effect" "control control"   "xvarmean xvarmean" ) 				
	estimates clear	
	}
	*xvar loop	



	
	
*Robustness - with Additional Controls 
	foreach extra in storms zhigh c.pctag#c.index  projbuildingxHEA projbuildingxHEA@projbuildingxTRA@projbuildingxEDU    {
	local extra=subinstr("`extra'","@"," ",.)
	
		foreach yvar in anysect  {
		local yvarshort=substr("`yvar'",1,9)
		
			foreach control in demogplus mun  {
			global controls ${c_`control'} 
					eststo a`yvarshort'`control': reg `yvar' eventviolent_mun `extra' i.month i.year i.provid $controls, cluster(munid)
					sum eventviolent_mun if e(sample)==1, d
					local xvarmean=round(r(mean),.01)
					local xvarsd=r(sd)*_b[eventviolent_mun]
					
					estadd ysumm
					estadd local control "`control'"				
					estadd local xvarmean "`xvarmean'"
					estadd local xvarsd "`xvarsd'"
				
			}
			*control loop	
		}
		*yvar loop end
		
	esttab a* using "${filename}.csv", star(* 0.10 ** 0.05 *** .01) title("Curative Care Robustness: With `extra'") ///
		se(a2) b(a2) append keep(*eventviolent_mun* `extra') staraux scalar("ymean Mean of DV" "xvarsd 1SD effect" "control control"   "xvarmean xvarmean" ) 				
	estimates clear	
	
	}
	*extra loop end
	
*Leads
	foreach control in  demogplus mun {
	global controls ${c_`control'} 
		
			eststo a`control': reg anysect le5_eventviolent_mun  i.month i.year i.provid  $controls , cluster(munid)
			estadd ysumm
			estadd local control "`control'"
			
			eststo a1`control': reg anysect le5_eventviolent_mun eventviolent_mun i.month i.year i.provid  $controls, cluster(munid)
			estadd ysumm
			estadd local control "`control'"

	}
	*control loop	

	esttab a* using "${filename}.csv", star(* 0.10 ** 0.05 *** .01) title("Curative Care Placebo") ///
		se(a2) b(a2) append keep(*eventviolent_mun* ) staraux scalar("ymean Mean of DV" "control control" ) 				
	estimates clear	
	
	


